<template>
    <fieldset>
         <legend>登入</legend>
         用户名:
         <input type="text" v-model="username">
         密码:
         <input type="text" v-model="password">
         <button @click="handleLogin">登入</button>
    </fieldset>
</template>

<script>
//as 就是起别名  然后* 就是全部
import * as Api from "@/api/index"
import { mapMutations ,mapState} from "vuex"
// import {loginApi} from "../api/index"
   export default {
      data(){
        return{
            username:"",
            password:""
        }
      },
      computed:{
        ...mapState("user",["userInfo"])
      },
      methods:{
        async handleLogin(){
            let obj = {
                 username: this.username,
                 password:this.password
            }
            let res = await Api.loginApi(obj);
            console.log(res);
            this.SET_USERINFO(res.userInfo);
            //  console.log(this.$store.state.user.userInfo)
            //获取数据后存到vuex里
            if(res.state){
                this.$router.push("/home")
            }
        },
        ...mapMutations("user",["SET_USERINFO"])
      }
   }
</script>